



<!doctype html>
<html lang="en" class="no-js">
  <head>
    
      <meta charset="utf-8">
      <meta name="viewport" content="width=device-width,initial-scale=1">
      <meta http-equiv="x-ua-compatible" content="ie=edge">
      
        <meta name="description" content="Here you can find all documents about QTrobot.">
      
      
        <link rel="canonical" href="https://luxai-qtrobot.github.io/examples/qt_motors_custom_controller/">
      
      
        <meta name="author" content="QTrobot">
      
      
        <meta name="lang:clipboard.copy" content="Copy to clipboard">
      
        <meta name="lang:clipboard.copied" content="Copied to clipboard">
      
        <meta name="lang:search.language" content="en">
      
        <meta name="lang:search.pipeline.stopwords" content="True">
      
        <meta name="lang:search.pipeline.trimmer" content="True">
      
        <meta name="lang:search.result.none" content="No matching documents">
      
        <meta name="lang:search.result.one" content="1 matching document">
      
        <meta name="lang:search.result.other" content="# matching documents">
      
        <meta name="lang:search.tokenizer" content="[\s\-]+">
      
      <link rel="shortcut icon" href="../../img/luxai-favicon.ico">
      <meta name="generator" content="mkdocs-1.1, mkdocs-material-4.6.3">
    
    
      
        <title>QTrobot Motors ROS controller - QTrobot Documentation</title>
      
    
    
      <link rel="stylesheet" href="../../assets/stylesheets/application.adb8469c.css">
      
        <link rel="stylesheet" href="../../assets/stylesheets/application-palette.a8b3c06d.css">
      
      
        
        
        <meta name="theme-color" content="#3f51b5">
      
    
    
      <script src="../../assets/javascripts/modernizr.86422ebf.js"></script>
    
    
      
        <link href="https://fonts.gstatic.com" rel="preconnect" crossorigin>
        <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,400i,700%7CRoboto+Mono&display=fallback">
        <style>body,input{font-family:"Roboto","Helvetica Neue",Helvetica,Arial,sans-serif}code,kbd,pre{font-family:"Roboto Mono","Courier New",Courier,monospace}</style>
      
    
    <link rel="stylesheet" href="../../assets/fonts/material-icons.css">
    
    
      <link rel="stylesheet" href="../../stylesheets/extra.css">
    
    
      
    
    
  </head>
  
    
    
    <body dir="ltr" data-md-color-primary="indigo" data-md-color-accent="indigo">
  
    <svg class="md-svg">
      <defs>
        
        
      </defs>
    </svg>
    <input class="md-toggle" data-md-toggle="drawer" type="checkbox" id="__drawer" autocomplete="off">
    <input class="md-toggle" data-md-toggle="search" type="checkbox" id="__search" autocomplete="off">
    <label class="md-overlay" data-md-component="overlay" for="__drawer"></label>
    
      <a href="#qtrobot-motors-ros-controller" tabindex="0" class="md-skip">
        Skip to content
      </a>
    
    
      <header class="md-header" data-md-component="header">
  <nav class="md-header-nav md-grid">
    <div class="md-flex">
      <div class="md-flex__cell md-flex__cell--shrink">
        <a href="https://luxai-qtrobot.github.io/" title="QTrobot Documentation" aria-label="QTrobot Documentation" class="md-header-nav__button md-logo">
          
            <img alt="logo" src="../../img/logo_luxai_white.png" width="24" height="24">
          
        </a>
      </div>
      <div class="md-flex__cell md-flex__cell--shrink">
        <label class="md-icon md-icon--menu md-header-nav__button" for="__drawer"></label>
      </div>
      <div class="md-flex__cell md-flex__cell--stretch">
        <div class="md-flex__ellipsis md-header-nav__title" data-md-component="title">
          
            <span class="md-header-nav__topic">
              QTrobot Documentation
            </span>
            <span class="md-header-nav__topic">
              
                QTrobot Motors ROS controller
              
            </span>
          
        </div>
      </div>
      <div class="md-flex__cell md-flex__cell--shrink">
        
          <label class="md-icon md-icon--search md-header-nav__button" for="__search"></label>
          
<div class="md-search" data-md-component="search" role="dialog">
  <label class="md-search__overlay" for="__search"></label>
  <div class="md-search__inner" role="search">
    <form class="md-search__form" name="search">
      <input type="text" class="md-search__input" aria-label="search" name="query" placeholder="Search" autocapitalize="off" autocorrect="off" autocomplete="off" spellcheck="false" data-md-component="query" data-md-state="active">
      <label class="md-icon md-search__icon" for="__search"></label>
      <button type="reset" class="md-icon md-search__icon" data-md-component="reset" tabindex="-1">
        &#xE5CD;
      </button>
    </form>
    <div class="md-search__output">
      <div class="md-search__scrollwrap" data-md-scrollfix>
        <div class="md-search-result" data-md-component="result">
          <div class="md-search-result__meta">
            Type to start searching
          </div>
          <ol class="md-search-result__list"></ol>
        </div>
      </div>
    </div>
  </div>
</div>
        
      </div>
      
    </div>
  </nav>
</header>
    
    <div class="md-container">
      
        
      
      
      <main class="md-main" role="main">
        <div class="md-main__inner md-grid" data-md-component="container">
          
            
              <div class="md-sidebar md-sidebar--primary" data-md-component="navigation">
                <div class="md-sidebar__scrollwrap">
                  <div class="md-sidebar__inner">
                    <nav class="md-nav md-nav--primary" data-md-level="0">
  <label class="md-nav__title md-nav__title--site" for="__drawer">
    <a href="https://luxai-qtrobot.github.io/" title="QTrobot Documentation" class="md-nav__button md-logo">
      
        <img alt="logo" src="../../img/logo_luxai_white.png" width="48" height="48">
      
    </a>
    QTrobot Documentation
  </label>
  
  <ul class="md-nav__list" data-md-scrollfix>
    
      
      
      


  <li class="md-nav__item">
    <a href="../.." title="Home" class="md-nav__link">
      Home
    </a>
  </li>

    
      
      
      


  <li class="md-nav__item">
    <a href="../../user-manual/" title="Quick Start" class="md-nav__link">
      Quick Start
    </a>
  </li>

    
      
      
      


  <li class="md-nav__item">
    <a href="../../api/" title="API Reference" class="md-nav__link">
      API Reference
    </a>
  </li>

    
      
      
      


  <li class="md-nav__item md-nav__item--nested">
    
      <input class="md-toggle md-nav__toggle" data-md-toggle="nav-4" type="checkbox" id="nav-4">
    
    <label class="md-nav__link" for="nav-4">
      FAQ
    </label>
    <nav class="md-nav" data-md-component="collapsible" data-md-level="1">
      <label class="md-nav__title" for="nav-4">
        FAQ
      </label>
      <ul class="md-nav__list" data-md-scrollfix>
        
        
          
          
          


  <li class="md-nav__item">
    <a href="../../FAQ/Audio/" title="Audio" class="md-nav__link">
      Audio
    </a>
  </li>

        
          
          
          


  <li class="md-nav__item">
    <a href="../../FAQ/Autostart/" title="Autostart" class="md-nav__link">
      Autostart
    </a>
  </li>

        
          
          
          


  <li class="md-nav__item">
    <a href="../../FAQ/Motors/" title="Motors" class="md-nav__link">
      Motors
    </a>
  </li>

        
          
          
          


  <li class="md-nav__item">
    <a href="../../FAQ/Network/" title="Network" class="md-nav__link">
      Network
    </a>
  </li>

        
          
          
          


  <li class="md-nav__item">
    <a href="../../FAQ/Miscellaneous/" title="Miscellaneous" class="md-nav__link">
      Miscellaneous
    </a>
  </li>

        
      </ul>
    </nav>
  </li>

    
      
      
      


  <li class="md-nav__item">
    <a href="../../demos/" title="Demos" class="md-nav__link">
      Demos
    </a>
  </li>

    
      
      
      


  <li class="md-nav__item">
    <a href="../" title="Examples" class="md-nav__link">
      Examples
    </a>
  </li>

    
      
      
      


  <li class="md-nav__item">
    <a href="../../author-note/" title="Author's Note" class="md-nav__link">
      Author's Note
    </a>
  </li>

    
  </ul>
</nav>
                  </div>
                </div>
              </div>
            
            
              <div class="md-sidebar md-sidebar--secondary" data-md-component="toc">
                <div class="md-sidebar__scrollwrap">
                  <div class="md-sidebar__inner">
                    
<nav class="md-nav md-nav--secondary">
  
  
    
  
  
    <label class="md-nav__title" for="__toc">Table of contents</label>
    <ul class="md-nav__list" data-md-scrollfix>
      
        <li class="md-nav__item">
  <a href="#what-it-does" class="md-nav__link">
    What it does?
  </a>
  
</li>
      
        <li class="md-nav__item">
  <a href="#compilation-and-build" class="md-nav__link">
    Compilation and build
  </a>
  
</li>
      
        <li class="md-nav__item">
  <a href="#configuration-and-launching" class="md-nav__link">
    Configuration and launching
  </a>
  
</li>
      
        <li class="md-nav__item">
  <a href="#re-launch-qt_motor-node" class="md-nav__link">
    Re-launch qt_motor node
  </a>
  
</li>
      
        <li class="md-nav__item">
  <a href="#testing" class="md-nav__link">
    Testing
  </a>
  
</li>
      
      
      
      
      
    </ul>
  
</nav>
                  </div>
                </div>
              </div>
            
          
          <div class="md-content">
            <article class="md-content__inner md-typeset">
              
                
                
                <h1 id="qtrobot-motors-ros-controller">QTrobot Motors ROS controller</h1>
<div class="admonition question">
<p>Get the full code in our <a href="https://github.com/luxai-qtrobot/tutorials/tree/master/examples">github tutorial repository.</a></p>
</div>
<p>This example shows how to write a new ROS controller for QTrobot. Before getting into that, make sure you know and understand what is <a href="http://wiki.ros.org/ros_control">ROS Conrol</a>.</p>
<h2 id="what-it-does">What it does?</h2>
<p>this controller simply play a predefined trajectory directly by commanding the QTrobot motors at hardware level.  You can use it as a simple template to implement more sophisticate controllers.  </p>
<h2 id="compilation-and-build">Compilation and build</h2>
<ul>
<li>
<p>copy <code class="codehilite"><span class="err">motors_custom_controller</span></code> to the <code class="codehilite"><span class="err">~/catckin_ws</span></code>on the RPI of QTrobot</p>
</li>
<li>
<p>build the example code:
<div class="codehilite"><pre><span></span><code><span class="err">cd ~/catckin_ws</span>
<span class="err">catkin_make --pkg motors_custom_controller</span>
</code></pre></div></p>
</li>
</ul>
<h2 id="configuration-and-launching">Configuration and launching</h2>
<ul>
<li>modify the qt_motor config file to define your new controller. to do that open <code class="codehilite"><span class="err">/opt/ros/kinetic/share/qt_motor/config/qtrobot-controller.yaml</span></code> file and add the following lines to the end of the file.
<div class="codehilite"><pre><span></span><code><span class="err">  custom:</span>
<span class="err">    type: motors_custom_controller/QTCustomController</span>
<span class="err">    myparam: bar</span>
</code></pre></div></li>
<li>modify qt_motor launch file to load and run your controller. to do that, open <code class="codehilite"><span class="err">/opt/ros/kinetic/share/qt_motor/launch/qt_motor.launch</span></code> and add <code class="codehilite"><span class="err">/qt_robot/custom</span></code> controller to <code class="codehilite"><span class="err">controller_manager</span></code> node. it should look like this:</li>
</ul>
<div class="codehilite"><pre><span></span><code><span class="err">&lt;!-- load the controllers --&gt;</span>
<span class="err"> &lt;node pkg=&quot;controller_manager&quot; name=&quot;controller&quot; type=&quot;spawner&quot; launch-prefix=&quot;bash -c &#39;sleep 15; $0 $@&#39; &quot; respawn=&quot;false&quot;</span>
<span class="err">       output=&quot;screen&quot; clear_params=&quot;true&quot;  args=&quot;/qt_robot/head_position</span>
<span class="err">                             /qt_robot/right_arm_position</span>
<span class="err">                             /qt_robot/left_arm_position</span>
<span class="err">                             /qt_robot/joints_state</span>
<span class="err">                             /qt_robot/motors</span>
<span class="err">                             /qt_robot/gesture</span>
<span class="err">                             /qt_robot/custom&quot;/&gt;</span>
</code></pre></div>

<h2 id="re-launch-qt_motor-node">Re-launch qt_motor node</h2>
<p>you can simply reboot the robot or launch the <code class="codehilite"><span class="err">qt_motor</span></code> node from terminal to see its output.
* stop the running instance:
<div class="codehilite"><pre><span></span><code><span class="err">ps -aux | grep qt_motor | grep SCREEN</span>
<span class="err">...</span>
<span class="err">kill xxx</span>
</code></pre></div></p>
<ul>
<li>launch <code class="codehilite"><span class="err">qt_motor</span></code> node
<div class="codehilite"><pre><span></span><code><span class="err">roslaunch qt_motor qt_motor.launch</span>
</code></pre></div></li>
</ul>
<p>you should see your controller (<code class="codehilite"><span class="err">QTCustomController</span></code>) running by checking the terminal output:
<div class="codehilite"><pre><span></span><code><span class="p">...</span><span class="w"></span>
<span class="o">[</span><span class="n">INFO</span><span class="o">]</span><span class="w"> </span><span class="o">[</span><span class="n">1576498210.924577</span><span class="o">]</span><span class="err">:</span><span class="w"> </span><span class="n">Controller</span><span class="w"> </span><span class="nl">Spawner</span><span class="p">:</span><span class="w"> </span><span class="n">Loaded</span><span class="w"> </span><span class="nl">controllers</span><span class="p">:</span><span class="w"> </span><span class="o">/</span><span class="n">qt_robot</span><span class="o">/</span><span class="n">head_position</span><span class="p">,</span><span class="w"> </span><span class="o">/</span><span class="n">qt_robot</span><span class="o">/</span><span class="n">right_arm_position</span><span class="p">,</span><span class="w"> </span><span class="o">/</span><span class="n">qt_robot</span><span class="o">/</span><span class="n">left_arm_position</span><span class="p">,</span><span class="w"> </span><span class="o">/</span><span class="n">qt_robot</span><span class="o">/</span><span class="n">joints_state</span><span class="p">,</span><span class="w"> </span><span class="o">/</span><span class="n">qt_robot</span><span class="o">/</span><span class="n">motors</span><span class="p">,</span><span class="w"> </span><span class="o">/</span><span class="n">qt_robot</span><span class="o">/</span><span class="n">gesture</span><span class="p">,</span><span class="w"> </span><span class="o">/</span><span class="n">qt_robot</span><span class="o">/</span><span class="n">custom</span><span class="w"></span>
<span class="o">[</span><span class="n"> INFO</span><span class="o">]</span><span class="w"> </span><span class="o">[</span><span class="n">1576498210.984396566</span><span class="o">]</span><span class="err">:</span><span class="w"> </span><span class="nl">QTMotorsController</span><span class="p">:</span><span class="w"> </span><span class="n">starting</span><span class="w"></span>
<span class="o">[</span><span class="n"> INFO</span><span class="o">]</span><span class="w"> </span><span class="o">[</span><span class="n">1576498210.985034385</span><span class="o">]</span><span class="err">:</span><span class="w"> </span><span class="nl">QTGestureController</span><span class="p">:</span><span class="w"> </span><span class="n">starting</span><span class="w"></span>
<span class="o">[</span><span class="n"> INFO</span><span class="o">]</span><span class="w"> </span><span class="o">[</span><span class="n">1576498210.985518609</span><span class="o">]</span><span class="err">:</span><span class="w"> </span><span class="nl">QTCustomController</span><span class="p">:</span><span class="w"> </span><span class="n">starting</span><span class="w"></span>
<span class="p">...</span><span class="w"></span>
</code></pre></div></p>
<h2 id="testing">Testing</h2>
<p>your custom controller implement a service to Start/Stop it.</p>
<ul>
<li>
<p>to start the trajectory player, open another termianl and
<div class="codehilite"><pre><span></span><code><span class="err">rosservice call /qt_robot/custom/startstop &quot;command: true&quot;</span>
</code></pre></div></p>
</li>
<li>
<p>to stop the trajectory player:
<div class="codehilite"><pre><span></span><code><span class="err">rosservice call /qt_robot/custom/startstop &quot;command: false&quot;</span>
</code></pre></div></p>
</li>
</ul>
                
                  
                
                
                  
                  <hr>
                  <div class="md-source-date">
                    <small>
                      
                        Last update: April 22, 2020
                      
                    </small>
                  </div>
                
              
              
                


              
            </article>
          </div>
        </div>
      </main>
      
        <!--
  Copyright (c) 2016-2020 Martin Donath <martin.donath@squidfunk.com>

  Permission is hereby granted, free of charge, to any person obtaining a copy
  of this software and associated documentation files (the "Software"), to
  deal in the Software without restriction, including without limitation the
  rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  sell copies of the Software, and to permit persons to whom the Software is
  furnished to do so, subject to the following conditions:

  The above copyright notice and this permission notice shall be included in
  all copies or substantial portions of the Software.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  IN THE SOFTWARE.
-->



<!-- Application footer -->
<footer id="footer" class="md-footer">

  <!-- Link to previous and/or next page -->
  

  <!-- Further information -->
  <div class="md-footer-meta md-typeset">
    <div class="md-footer-meta__inner md-grid">
      <!-- Copyright and theme information -->
      <div class="md-footer-copyright">
        
          <div class="md-footer-copyright__highlight">
            &copy; Copyright &copy; 2020 LuxAI S.A.
          </div>
        
      </div>

      <!-- Social links -->
      
  <div class="md-footer-social">
    <link rel="stylesheet" href="../../assets/fonts/font-awesome.css">
    
      <a href="https://github.com/luxai-qtrobot" target="_blank" rel="noopener" title="github" class="md-footer-social__link fa fa-github"></a>
    
      <a href="https://twitter.com/qtrobot" target="_blank" rel="noopener" title="twitter" class="md-footer-social__link fa fa-twitter"></a>
    
      <a href="https://www.linkedin.com/company/luxai/" target="_blank" rel="noopener" title="linkedin" class="md-footer-social__link fa fa-linkedin"></a>
    
      <a href="https://www.facebook.com/luxAI/" target="_blank" rel="noopener" title="facebook" class="md-footer-social__link fa fa-facebook"></a>
    
      <a href="https://www.youtube.com/channel/UCAY0H0HaqQL1GE7lO_iSpbg" target="_blank" rel="noopener" title="youtube" class="md-footer-social__link fa fa-youtube"></a>
    
  </div>

    </div>
  </div>
</footer>
      
    </div>
    
      <script src="../../assets/javascripts/application.c33a9706.js"></script>
      
      <script>app.initialize({version:"1.1",url:{base:"../.."}})</script>
      
        <script src="../../javascripts/extra.js"></script>
      
    
  </body>
</html>